package com.ojoin.trade.common.web.service.impl;

import org.springframework.stereotype.Service;

import redis.clients.jedis.JedisPubSub;
import redis.clients.util.SafeEncoder;

import com.ojoin.trade.common.utils.CommonUtils;
import com.ojoin.trade.common.utils.JedisUtils;
import com.ojoin.trade.common.utils.json.JSONUtils;
import com.ojoin.trade.common.web.service.MQService;

@Service
public class JedisMQServiceImpl implements MQService {
 
	
	@Override
	public void publishByJSON(String channel, Object value) {
        if(value instanceof String){
        	JedisUtils.publish(channel,(String)value);
        }else {
        	JedisUtils.publish(channel,JSONUtils.toJSONString(value));
        } 
	}

	@Override
	public void subscriber(String channel, Object PubSub) {
		JedisUtils.subscriber(channel, (JedisPubSub) PubSub);
	}

	@Override 
	public void publishByObjectByte(String channel, Object value) {
		JedisUtils.publish(SafeEncoder.encode(channel),CommonUtils.serialize(value));
		
	}
     
	@Override
	public void publishByObjectString(String channel, Object value,String charset) {
		JedisUtils.publish(channel,CommonUtils.serializeToString(value,charset)); 
		
	}

	@Override
	public void publishByObjectString(String channel, Object value) {
		publishByObjectString(channel, value,"ISO-8859-1"); 
		
	}

}
